package com.web.dao;

import com.github.pagehelper.Page;
import com.web.controller.web.WebSysLogController;
import com.web.entity.MerchantDetail;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author FDjavaone
 */
public interface MerchantDetailMapper {


    @Delete({
            "delete from t_merchant_detail",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into t_merchant_detail (a_id, content,",
            " detail,name,phone,from_num,bal,consumer,consumer_id,store,store_id,type,total_bal, create_time, ",
            " modify_time)",
            " values (#{aId,jdbcType=BIGINT}, #{content,jdbcType=VARCHAR}, ",
            " #{detail,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR},#{phone,jdbcType=VARCHAR},#{fromNum,jdbcType=VARCHAR},#{bal,jdbcType=VARCHAR}," +
                    " #{consumer,jdbcType=VARCHAR},#{consumerId,jdbcType=BIGINT},#{store,jdbcType=VARCHAR},#{storeId,jdbcType=BIGINT},#{type,jdbcType=INTEGER},#{totalBal,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ",
            " #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insert(MerchantDetail record);

    @InsertProvider(type = MerchantDetailSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insertSelective(MerchantDetail record);


    @Select({
            "select",
            " id, a_id, content, detail,name,phone,from_num,bal,consumer,consumer_id,store,store_id,type,total_bal, create_time, modify_time",
            " from t_merchant_detail",
            " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "a_id", property = "aId", jdbcType = JdbcType.BIGINT),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "detail", property = "detail", jdbcType = JdbcType.VARCHAR),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "from_num", property = "fromNum", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bal", property = "bal", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consumer", property = "consumer", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consumer_id", property = "consumerId", jdbcType = JdbcType.BIGINT),
            @Result(column = "store", property = "store", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_id", property = "storeId", jdbcType = JdbcType.BIGINT),
            @Result(column = "type", property = "type", jdbcType = JdbcType.INTEGER),
            @Result(column = "total_bal", property = "totalBal", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    MerchantDetail selectByPrimaryKey(Long id);


    @UpdateProvider(type = MerchantDetailSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(MerchantDetail record);

    @Update({
            "update t_merchant_detail",
            " set a_id = #{aId,jdbcType=BIGINT},",
            " content = #{content,jdbcType=VARCHAR},",
            " detail = #{detail,jdbcType=VARCHAR},",
            " name = #{name,jdbcType=VARCHAR},",
            " phone = #{phone,jdbcType=VARCHAR},",
            " from_num = #{fromNum,jdbcType=VARCHAR},",
            " bal = #{bal,jdbcType=VARCHAR},",
            " consumer = #{consumer,jdbcType=VARCHAR},",
            " consumer_id = #{consumerId,jdbcType=BIGINT},",
            " store = #{store,jdbcType=VARCHAR},",
            " store_id = #{storeId,jdbcType=BIGINT},",
            " type = #{type,jdbcType=INTEGER},",
            " total_bal = #{totalBal,jdbcType=VARCHAR},",
            " create_time = #{createTime,jdbcType=TIMESTAMP},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(MerchantDetail record);

    @Select({
            "select",
            " id, a_id, content, detail,name,phone,from_num,bal,consumer,consumer_id,store,store_id,type,total_bal, create_time, modify_time",
            " from t_merchant_detail",
            " where a_id = #{id,jdbcType=BIGINT}  order by create_time desc"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "a_id", property = "aId", jdbcType = JdbcType.BIGINT),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "detail", property = "detail", jdbcType = JdbcType.VARCHAR),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "from_num", property = "fromNum", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bal", property = "bal", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consumer", property = "consumer", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consumer_id", property = "consumerId", jdbcType = JdbcType.BIGINT),
            @Result(column = "store", property = "store", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_id", property = "storeId", jdbcType = JdbcType.BIGINT),
            @Result(column = "type", property = "type", jdbcType = JdbcType.INTEGER),
            @Result(column = "total_bal", property = "totalBal", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<MerchantDetail> selectByAid(Long id);

    @SelectProvider(type = MerchantDetailSqlProvider.class, method = "selectAllMerchantLogs")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "a_id", property = "aId", jdbcType = JdbcType.BIGINT),
            @Result(column = "content", property = "content", jdbcType = JdbcType.VARCHAR),
            @Result(column = "detail", property = "detail", jdbcType = JdbcType.VARCHAR),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "from_num", property = "fromNum", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bal", property = "bal", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consumer", property = "consumer", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consumer_id", property = "consumerId", jdbcType = JdbcType.BIGINT),
            @Result(column = "store", property = "store", jdbcType = JdbcType.VARCHAR),
            @Result(column = "store_id", property = "storeId", jdbcType = JdbcType.BIGINT),
            @Result(column = "type", property = "type", jdbcType = JdbcType.INTEGER),
            @Result(column = "total_bal", property = "totalBal", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    Page<MerchantDetail> selectAllMerchantLogs(WebSysLogController.DetailsColumns detailsColumns);
}